/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package com.xiashitech.agent.instrumentation.redis.redisson.v317.inst;

import com.google.auto.service.AutoService;
import com.xiashitech.agent.instrumentation.redis.redisson.v317.inst.XSRedisCommandDataInstrumentation;
import com.xiashitech.agent.instrumentation.redis.redisson.v317.inst.XSRedisConnectionInstrumentation;
import com.xiashitech.agent.rule.usermatch.Register;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import net.bytebuddy.matcher.ElementMatcher;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
import static java.util.Arrays.asList;

@AutoService(InstrumentationModule.class)
public class XSRedissonInstrumentationModule extends InstrumentationModule {

  public XSRedissonInstrumentationModule() {
    super("xs.redisson", "xs.redisson-3.17");
  }

  @Override
  public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
    return hasClassesNamed("org.redisson.api.RFunction");
  }

  @Override
  public List<TypeInstrumentation> typeInstrumentations() {
    return asList(new XSRedisConnectionInstrumentation(), new XSRedisCommandDataInstrumentation());
  }

  @Override
  public List<String> getAdditionalHelperClassNames() {
    List<String> helperClassNames = new ArrayList();
    helperClassNames.addAll(Arrays.asList("com.xiashitech.agent.instrumentation.redis.redisson.v317.XSRedissonSingletons",
            "com.xiashitech.agent.instrumentation.redis.XSJedisAttributesExtractor",
            "com.xiashitech.agent.instrumentation.redis.redisson.XSRedissonRequest",
            "com.xiashitech.agent.instrumentation.redis.redisson.XSPromiseWrapper",
            "com.xiashitech.agent.instrumentation.redis.redisson.XSEndOperationListener",
            "com.xiashitech.agent.instrumentation.redis.redisson.XSCompletableFutureWrapper",
            "com.xiashitech.agent.instrumentation.redis.redisson.XSCompletableFuture",
            "com.xiashitech.agent.instrumentation.redis.constants.CommandNames",
            "com.xiashitech.agent.utils.SessionUtil"));
    helperClassNames.addAll(Register.registUserMatch());
    return helperClassNames;
  }
}
